<%--
  Created by IntelliJ IDEA.
  User: 岳冉
  Date: 2020/5/7
  Time: 18:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath();%>
<jsp:include page="../inc/header.jsp"></jsp:include>
<!-- Page Heading Section Start -->
<div class="page-heading-section section bg-parallax" data-bg-image="${pageContext.request.contextPath}/assets/images/bg/bg-1.jpg" data-overlay="50">
    <div class="container">
        <div class="page-heading-content text-center">
            <h3 class="title">浏览工作</h3>
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="${pageContext.request.contextPath}/web/index">首页</a></li>
                <li class="breadcrumb-item active">职位</li>
            </ol>
        </div>
    </div>
</div>
<!-- Page Heading Section End -->

<!-- Recent Jobs Start -->
<div class="section section-padding">
    <div class="container">
        <div class="row mb-n5">

            <div class="col-lg-8 col-12 mb-5 pr-lg-5">


                <!-- Job List Toolbar End -->
                <div id="listData">

                    


                </div>


            </div>

            <!-- Job Sidebar Wrap Start -->
            <div class="col-lg-4 col-12 mb-5">
                <div class="sidebar-wrap">
                    <!-- Sidebar (搜索) Start -->
                    <div class="sidebar-widget">
                        <div class="inner">
                            <h6 class="title">搜索</h6>
                            <input onblur="jobName()" class="name" type="text" placeholder="例如：Java工程师">
                        </div>
                    </div>
                    <!-- Sidebar (Search) End -->

                    <!-- Sidebar (行业类型) Start -->
                    <div class="sidebar-widget">
                        <div class="inner">
                            <h6 class="title">行业类型</h6>
                            <select class="industry" name="industry">
                                <option value="0">不限</option>
                                <c:forEach items="${requestScope.industries}" var="industry">
                                    <option value="${industry.id}">${industry.industryName}</option>
                                </c:forEach>
                            </select>
                        </div>
                    </div>
                    <!-- Sidebar (Category) End -->
                    <!-- Sidebar (职位类型) Start -->
                    <div class="sidebar-widget">
                        <div class="inner">
                            <h6 class="title">职位类型</h6>
                            <select  class="positionType">

                            </select>
                        </div>
                    </div>
                    <!-- Sidebar (Category) End -->

                    <!-- Sidebar (城市) Start -->
                    <div class="sidebar-widget">
                        <div class="inner">
                            <h6 class="title">城市</h6>
                            <input onblur="cityName()" class="city" type="text" placeholder="城市">
                        </div>
                    </div>
                    <!-- Sidebar (Location) End -->

                    <!-- Sidebar (工作类型) Start -->
                    <div class="sidebar-widget">
                        <div class="inner">
                            <h6 class="title">工作类型</h6>
                            <div class="custom-control custom-checkbox mb-1">
                                <input onclick="attr()" type="radio" name="positionAttr" value="0" class="custom-control-input" id="jobtype0">
                                <label class="custom-control-label" for="jobtype0">不限</label>
                            </div>
                            <c:forEach items="${requestScope.positionAttrs}" var="positionAttr">
                                <div class="custom-control custom-checkbox mb-1">
                                    <input onclick="attr()" type="radio" name="positionAttr" value="${positionAttr.id}" class="custom-control-input" id="jobType${positionAttr.id}">
                                    <label class="custom-control-label" for="jobType${positionAttr.id}">${positionAttr.attr}</label>
                                </div>
                            </c:forEach>
                        </div>
                    </div>
                    <!-- Sidebar (Job Type) End -->

                    <!-- Sidebar (薪资) Start -->
                    <div class="sidebar-widget">
                        <div class="inner">
                            <h6 class="title">薪资范围</h6>
                            <input type="text" onblur="salaryMin()" class="range-slider1"/> ~
                            <input type="text" onblur="salaryMax()" class="range-slider2"/>
                        </div>
                    </div>
                    <!-- Sidebar (Salary Range) End -->

                    <!-- Sidebar (工作经验) Start -->
                    <div class="sidebar-widget">
                        <div class="inner">
                            <h6 class="title">工作经验</h6>
                            <c:forEach items="${requestScope.workTimes}" var="workTime">
                                <div class="custom-control custom-radio mb-1">
                                    <input type="radio" onclick="workExp()" value="${workTime.id}" class="custom-control-input" name="workTime" id="jobExperince${workTime.id}">
                                    <label class="custom-control-label" for="jobExperince${workTime.id}">${workTime.workExpTime}</label>
                                </div>
                            </c:forEach>
                        </div>
                    </div>
                    <!-- Sidebar (Experince) End -->

                    <!-- Sidebar (学历) Start -->
                    <div class="sidebar-widget">
                        <div class="inner">
                            <h6 class="title">学历</h6>
                            <c:forEach items="${requestScope.educationalTypes}" var="educationalType">
                                <div class="custom-control custom-radio mb-1">
                                    <input onclick="educationalType()" value="${educationalType.id}" type="radio" class="custom-control-input" name="educationalBackgroundType" id="jobQualification${educationalType.id}">
                                    <label class="custom-control-label" for="jobQualification${educationalType.id}">${educationalType.educationalBackgroundTypeName}</label>
                                </div>
                            </c:forEach>
                        </div>
                    </div>
                    <!-- Sidebar (Qualification) End -->
                </div>
            </div>
            <!-- Job Sidebar Wrap End -->

        </div>
    </div>
</div>
<!-- Recent Jobs End -->
<script src="${pageContext.request.contextPath}/static/js/jquery-3.4.1.min.js"></script>
<script>
    $(function () {
        search(1,10,null,null,null,null,null,null,null,null);
        var industryId = $(".industry").val();
        function findPositionType() {
            $.ajax({
                url:"<%=path%>/web/job/findPositionType",
                type:"post",
                async:"false",
                data:"industryId="+industryId,
                success:function (data) {
                    var positionType = $(".positionType");
                    positionType.html("");
                    positionType.append("<option value=\"0\">不限</option>");
                    $.each(data,function (i,object) {
                        positionType.append("<option value=\""+object.id+"\">"+object.positionTypeName+"</option>");
                    });
                }
            });
        }
        $(".industry").change(function () {
            industryId = $(".industry").val();
            findPositionType();
        });
        findPositionType();
        $(".positionType").change(function () {
            getValue();
        });
    });
    function search(pageNum,pageSize,name,positionType,city,positionAttr,salaryMin,salaryMax,workTime,educationalBackgroundType) {
        $.ajax({
            type:"post",
            url:"${pageContext.request.contextPath}/web/job/search",
            async:"false",
            data:{pageNum:pageNum,pageSize:pageSize,name:name,positionTypeId:positionType,cityName:city,positionAttrId:positionAttr,salaryMin:salaryMin,salaryMax:salaryMax,workTimeId:workTime,educationalBackgroundTypeId:educationalBackgroundType},
            success:function (res) {
                if(res!=null){
                    $("#listData").html(res);
                }
            }
        });
    }
    function page(i) {
        var name = $(".name").val();
        var positionType = $(".positionType").val();
        var city = $(".city").val();
        var positionAttr = $("input[name='positionAttr']:checked").val();
        var salaryMin = $(".range-slider1").val();
        var salaryMax = $(".range-slider2").val();
        var workTime = $("input[name='workTime']:checked").val();
        var educationalBackgroundType = $("input[name='educationalBackgroundType']:checked").val();
        search(i,10,name,positionType,city,positionAttr,salaryMin,salaryMax,workTime,educationalBackgroundType);
    }
    function jobName() {
        getValue();
    }
    function positionType() {
        getValue();
    }
    function cityName() {
        getValue();
    }
    function attr() {
        getValue();
    }
    function salaryMin() {
        getValue();
    }
    function salaryMax() {
        getValue();
    }
    function workExp() {
        getValue();
    }
    function educationalType() {
        getValue();
    }
    function getValue() {
        var name = $(".name").val();
        var positionType = $(".positionType").val();
        var city = $(".city").val();
        var positionAttr = $("input[name='positionAttr']:checked").val();
        var salaryMin = $(".range-slider1").val();
        var salaryMax = $(".range-slider2").val();
        var workTime = $("input[name='workTime']:checked").val();
        var educationalBackgroundType = $("input[name='educationalBackgroundType']:checked").val();
        // console.log("name:"+name);
        // console.log("positionType:"+positionType);
        // console.log("city:"+city);
        // console.log("positionAttr:"+positionAttr);
        // console.log("salaryMin:"+salaryMin);
        // console.log("salaryMax:"+salaryMax);
        // console.log("workTime:"+workTime);
        // console.log("educationalBackgroundType:"+educationalBackgroundType);
        search(1,10,name,positionType,city,positionAttr,salaryMin,salaryMax,workTime,educationalBackgroundType)
    }
</script>
<jsp:include page="../inc/footer.jsp"></jsp:include>